package org.cqut.system.work_submit.controller;

import org.cqut.framework.web.response.ResultInfo;
import org.cqut.framework.web.response.Status;
import org.cqut.system.work_submit.domain.WorkSubmit;
import org.cqut.system.work_submit.service.WorkSubmitService;
import org.cqut.system.work_submit.vo.RecordListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author XiAoXu
 * @date 2021/11/13 17:11
 * @description
 */
@RestController
@RequestMapping("/workSubmit")
public class WorkSubmitController {
    @Autowired
    private WorkSubmitService workSubmitService;

    @RequestMapping("/recordList")
    public ResultInfo recordList(@RequestBody Map<String,Object> map) {
        List<RecordListVo> recordList = workSubmitService.getRecordList(map);
        if (recordList != null) {
            return new ResultInfo(Status.QUERY_DETAILS_SUCCESS.code, Status.QUERY_DETAILS_SUCCESS.message, recordList);
        } else {
            return new ResultInfo(Status.QUERY_DETAILS_ERROR.code, Status.QUERY_DETAILS_ERROR.message);
        }
    }

    @RequestMapping(method = RequestMethod.POST,path = "/score")
    public ResultInfo score(@RequestBody WorkSubmit workSubmit){
        boolean flag = workSubmitService.saveGrade(workSubmit);
        if (flag) {
            return new ResultInfo(Status.SUCCESS.code, Status.SUCCESS.message);
        } else {
            return new ResultInfo(Status.WARN.code, Status.WARN.message);
        }
    }
}
